package com.azzcs.emailservice.service.impl;

import com.azzcs.emailservice.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.Message;
import org.springframework.util.StringUtils;

/**
 * @Author: wzg
 * @Date: 2021/2/24 上午11:59
 */
@EnableBinding(Sink.class)
public class MessageService {

    @Autowired
    private EmailService emailService;

    @StreamListener(Sink.INPUT)
    public void receiveMessage(Message<String> message){
        String payload = message.getPayload();
        if(!StringUtils.hasLength(payload)){
           return;
        }
        String[] split = payload.split("#");
        emailService.sendCreateCodeEmail(split[0],split[1]);
    }
}
